package com.example.canvastest;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by 700 on 2018/7/30.
 */

public class SignalLightView extends View {
    private int count=0;
    public SignalLightView(Context context, AttributeSet attrs,
                        int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setFocusable(true);
        setFocusableInTouchMode(true);
    }

    public SignalLightView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setFocusable(true);
        setFocusableInTouchMode(true);
    }

    public SignalLightView(Context context) {
        super(context);
        setFocusable(true);
        setFocusableInTouchMode(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        if(count<100){
            count++;
        }else{
            count=0;
        }
        Paint paint=new Paint();
        paint.setStrokeWidth(3.0f);
        switch(count%4){
            case 0:
                paint.setColor(Color.GREEN);
                break;
            case 1:
                paint.setColor(Color.RED);
                break;
            case 2:
                paint.setColor(Color.BLUE);
                break;
            case 3:
                paint.setColor(Color.YELLOW);
                break;
            default:
                paint.setColor(Color.WHITE);
                break;
        }
        canvas.drawCircle(80, 160, 50, paint);// 画圆，圆心的坐标(cx,cy)和半径radius
    }
}